package com.ruoyi.aero.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.aero.domain.StaffInfo;
import com.ruoyi.aero.service.IStaffInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工信息Controller
 * 
 * @author swb
 * @date 2024-06-04
 */
@RestController
@RequestMapping("/aero/staff")
public class StaffInfoController extends BaseController
{
    @Autowired
    private IStaffInfoService staffInfoService;

    /**
     * 查询员工信息列表
     */
    @PreAuthorize("@ss.hasPermi('aero:staff:list')")
    @GetMapping("/list")
    public TableDataInfo list(StaffInfo staffInfo)
    {
        startPage();
        List<StaffInfo> list = staffInfoService.selectStaffInfoList(staffInfo);
        return getDataTable(list);
    }

    /**
     * 根据岗位查询员工信息列表 只查询在职
     * @param postNo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('aero:staff:list')")
    @GetMapping("/listByPost/{postNo}")
    public AjaxResult listByPost(@PathVariable("postNo") String postNo)
    {
        // 只查询在职
        return AjaxResult.success(staffInfoService.selectStaffInfoListByPost(postNo));
    }

    /**
     * 查询车间负责人候选人
     * @return
     */
    @PreAuthorize("@ss.hasPermi('aero:staff:list')")
    @GetMapping("/workshopCandidateList")
    public AjaxResult selectWorkshopCandidate() {
        return success(staffInfoService.selectWorkshopCandidate());
    }

    /**
     * 查询班组负责人候选人
     * @return
     */
    @PreAuthorize("@ss.hasPermi('aero:staff:list')")
    @GetMapping("/groupCandidateList")
    public AjaxResult selectGroupCandidate() {
        return success(staffInfoService.selectGroupCandidate());
    }

    /**
     * 导出员工信息列表
     */
    @PreAuthorize("@ss.hasPermi('aero:staff:export')")
    @Log(title = "员工信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StaffInfo staffInfo)
    {
        List<StaffInfo> list = staffInfoService.selectStaffInfoList(staffInfo);
        ExcelUtil<StaffInfo> util = new ExcelUtil<StaffInfo>(StaffInfo.class);
        util.exportExcel(response, list, "员工信息数据");
    }

    /**
     * 获取员工信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('aero:staff:query')")
    @GetMapping(value = "/{staffId}")
    public AjaxResult getInfo(@PathVariable("staffId") String staffId)
    {
        return success(staffInfoService.selectStaffInfoByStaffId(staffId));
    }

    /**
     * 新增员工信息
     */
    @PreAuthorize("@ss.hasPermi('aero:staff:add')")
    @Log(title = "员工信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StaffInfo staffInfo)
    {
        return toAjax(staffInfoService.insertStaffInfo(staffInfo));
    }

    /**
     * 修改员工信息
     */
    @PreAuthorize("@ss.hasPermi('aero:staff:edit')")
    @Log(title = "员工信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StaffInfo staffInfo)
    {
        return toAjax(staffInfoService.updateStaffInfo(staffInfo));
    }

    /**
     * 删除员工信息
     */
    @PreAuthorize("@ss.hasPermi('aero:staff:remove')")
    @Log(title = "员工信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{staffIds}")
    public AjaxResult remove(@PathVariable String[] staffIds)
    {
        return toAjax(staffInfoService.deleteStaffInfoByStaffIds(staffIds));
    }
}
